<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML" 4.01"//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- Created: August 17, 2001-->
<!--
$Id: RepDate.php,v 1.6 2001/11/02 19:29:33 eugenem Exp $
$Header: /export/home/eugenem/public_html/ComplianceReports/RCS/RepDate.php,v 1.6 2001/11/02 19:29:33 eugenem Exp $
$Log: RepDate.php,v $
Revision 1.6  2001/11/02 19:29:33  eugenem
Changed test conditions on the date in the SQL query to <= and >= because it was skipping the start and end dates.

Revision 1.5  2001/11/02 19:07:14  eugenem
Moved HTTP_*_VARS processing to dbc.inc

Revision 1.4  2001/11/02 14:58:22  eugenem
Moved database connect statements to a separate file.

Revision 1.3  2001/10/23 20:37:41  eugenem
Made SurveyID column a link to ResolveRecommendations.php so that recommendations for that survey can be viewed.

Revision 1.2  2001/10/23 19:16:43  eugenem
Made Description column a link to RepMachine.php so that Machine info can be displayed by clicking on the machine description.

Revision 1.1  2001/08/17 18:36:48  eugenem
Initial revision

-->

<html>
<head>
<title>Radiological Equipment Database</title>
<meta name="author" content="Eugene Mah">
<link rev="made" href="mailto:eugenem@ix.netcom.com">
<link rev="home" href="http://home.netcom.com/~eugenem/">
<meta name="description" content="">
<meta name="Keywords" content="">
<meta name="Reply-to" content="eugenem@ix.netcom.com">
<META http-equiv="PICS-Label" content='(PICS-1.1 "http://www.classify.org/safesurf/" l r (SS~~0001))'>
<?PHP
require('functions.inc');
require('dbc.inc');

$today = date("Ymd");  // Get today's date in YYYYMMDD format
$year = date("Y");
$month = date("m");
$day = date("d");
/*
  Establish date ranges.  Each of these are strings of the form
  startdate:enddate which will be split before using in a query.
*/
$thismonth = date("Ymd",mktime(0,0,0,$month,1,$year)) . ":" . $today;
$lastmonth = date("Ymd",mktime(0,0,0,$month-1,1,$year)) . ":" . date("Ymd",mktime(0,0,0,$month,0,$year));
$last3m = date("Ymd",mktime(0,0,0,$month-3,1,$year)) . ":" . $today;
$last6m = date("Ymd",mktime(0,0,0,$month-6,1,$year)) . ":" . $today;
$curryear = date("Ymd",mktime(0,0,0,1,1,$year)) . ":" . $today;
$lastyear = date("Ymd",mktime(0,0,0,1,1,$year-1)) . ":" . date("Ymd",mktime(0,0,0,12,31,$year-1));
$last12m = date("Ymd",mktime(0,0,0,$month,$day,$year-1)) . ":" . $today;

?>
</head>

<body>
<h1>Radiological Equipment Database</h1>
<h2>List Surveys by Date</h2>
<?PHP
if (isset($startend)) {
  /*
    $startend is a string containing the date range in the form
    YYYYMMDD:YYYYMMDD where the first YYYYMMDD is the start date
    and the second YYYYMMDD is the end date.
    First we need to parse the string.
  */
  $start = substr($startend,0,8);
  $end = substr($startend,9,8);
  $query = "SELECT Survey2Machine.MachineID,Survey2Machine.SurveyID,TestDate,TestType,Description,Accession,Location 
            FROM TestDates
			LEFT JOIN Survey2Machine USING (SurveyID)
			LEFT JOIN Machines ON Survey2Machine.MachineID = Machines.MachineID
			LEFT JOIN Location USING (LocationID),TestType
			WHERE (TestDate >= $start AND TestDate <= $end) 
			AND Status=\"Active\" 
			AND TestType.TypeID=TestDates.TypeID 
			ORDER BY TestDate";
  if (!empty($sortby)) {
    while (list($name,$id) = each($sortby)) {
      $query .= ",$id";
    }
  }
  $result = mysql_query($query)
    or die ("Query failed: $query<br>\n");
?>
<table border=1>
  <tr>
    <th>SurveyID</th><th>TestDate</th><th>TestType</th><th>Accession</th><th>Description</th>
  </tr>
<?PHP
  // Spit the results out into a table
  while ($row= mysql_fetch_array($result)) {
    echo "<tr>\n";
    echo "<td><a href=\"SurveyResRec.php?SurveyID=" . $row['SurveyID'];
    echo "\">" . $row['SurveyID'] . "</a></td>\n";
    echo "<td>" . $row['TestDate'] . "</td>\n";
    echo "<td>" . $row['TestType'] . "</td>\n";
    echo "<td>" . $row['Accession'] . "</td>\n";
    echo "<td><a href=\"RepMachine.php?MachID=" . $row['MachineID'];
    echo "\">" . $row['Description'] . "</a></td>\n";
    echo "<tr>\n";
  }
}
?>
</table>
<form action="RepDate.php" method="POST">
<p>Select date range:
<select name="startend" size=1>
  <option>Select a date range
  <option value="<?PHP echo $thismonth; ?>">This month
  <option value="<?PHP echo $lastmonth;?>">Last month
  <option value="<?PHP echo $last3m;?>">Last 3 months
  <option value="<?PHP echo $last6m;?>">Last 6 months
  <option value="<?PHP echo $curryear;?>">This year
  <option value="<?PHP echo $lastyear;?>">Last year
  <option value="<?PHP echo $last12m;?>">Last 12 months
</select>
</p>
<!--
<p>Custom date: <input type="TEXT" name="startend" size="20"> (YYYYMMDD:YYYYMMDD)
</p>
-->
<p>
Sort results by: 
<input type="CHECKBOX" name="sortby[]" value="Model">Model
<input type="CHECKBOX" name="sortby[]" value="Description">Description
<input type="CHECKBOX" name="sortby[]" value="Location">Location
</p>
<p><input type="SUBMIT" value="Search"> / <input type="RESET" value="Reset"> / <a href="index.html" target="_top" >Main</a></p>
</form>
</body>
</html>
